[text-fragment] Fix prefix matching edge case The current algorithm first finds a |prefix|, then checks if the immediate following text is the |search_text|. If it is it'll advance |search_start| to the end of the |search_text| so it can confirm it's followed by the |suffix| text. However, this means that if the |suffix| text doesn't match, the next iteration of the algorithm will start searching for the |prefix| at the end of the |search_text|. This is a problem if the |search_text| == |prefix| because we've now skipped the |search_text| part of the range for prefix matching. E.g. With prefix=foo search_text=foo suffix=bar we'll fail to match: foo foo foo bar Because the first iteration of the loop will use the first "foo" as the prefix, and the next iteration will use the third "foo" as the prefix; we skip the second. Bug: 1054243 Change-Id: I62b8a32f89c987e5bed8ea439ae1b7d53d12436d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2065979 Reviewed-by: Nick Burris <nburris@chromium.org> Commit-Queue: David Bokan <bokan@chromium.org> Cr-Commit-Position: refs/heads/master@{#743108} 
diff --git a/scroll-to-text-fragment/scroll-to-text-fragment-target.html b/scroll-to-text-fragment/scroll-to-text-fragment-target.html index b06f3c8..b2be851 100644 --- a/scroll-to-text-fragment/scroll-to-text-fragment-target.html +++ b/scroll-to-text-fragment/scroll-to-text-fragment-target.html 
@@ -74,7 +74,11 @@  </style>  <body>  <div id="element" class="scroll-section">Element</div> - <p id="text" class="scroll-section">This is a test page !$'()*+./:;=?@_~ &,- &#x30cd;&#x30b3;</p> + <p id="text" class="scroll-section"> + This is a test page !$'()*+./:;=?@_~ &,- &#x30cd;&#x30b3; + <br> + foo foo foo bar bar bar + </p>  <p id="more-text" class="scroll-section">More test page text</p>  <div class="scroll-section">  <div> 
diff --git a/scroll-to-text-fragment/scroll-to-text-fragment.html b/scroll-to-text-fragment/scroll-to-text-fragment.html index f0b167a..73931d4 100644 --- a/scroll-to-text-fragment/scroll-to-text-fragment.html +++ b/scroll-to-text-fragment/scroll-to-text-fragment.html 
@@ -61,6 +61,12 @@  expect_position: 'text',  description: 'Exact text with prefix and suffix should match text'  }, + // Test tricky edge case where prefix and query are equal + { + fragment: '#:~:text=foo-,foo,-bar', + expect_position: 'text', + description: 'Exact text with prefix and suffix and query equals prefix.' + },  // Test text range matching, with all combinations of context terms  {  fragment: '#:~:text=this,page',